package com.study.leetcode;

import java.util.ArrayList;
import java.util.List;

public class _22 {
    public static void helper(List<String> list, String temp, int open, int close, int n) {
        if (open == n && close == n) {
            list.add(temp);
            return;
        }
        if (open < n) {
            helper(list, temp + "(", open + 1, close, n);
        }
        if (close < open) {
            helper(list, temp + ")", open, close + 1, n);
        }
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        helper(list, "", 0, 0, 3);
        System.out.println(list.toString());
    }
}
